
from django.db import models
from datetime import datetime

# Create your models here.


# 商家信息表
class BusUserModel(models.Model):
    b_name = models.CharField('用户名',max_length=64,default='')
    password = models.CharField('密码',max_length=256,default='')
    nickname = models.CharField('昵称',max_length=64,default='')
    portrait = models.CharField('头像',max_length=256,default='')
    gender = models.CharField('性别',max_length=16,default='')
    mobile = models.CharField('手机号',max_length=16,default='')
    person = models.CharField('法人',max_length=64,default='')
    business_time = models.DateTimeField('营业时间',default=datetime.now())
    member = models.IntegerField('会员级别 （0普通 1贵尊 2超级）',default=0)
    freeze = models.IntegerField('是否冻结（1冻结 2不冻结）', default=2)
    establish_time = models.DateTimeField('创建时间', default=datetime.now())
    change_time = models.DateTimeField('更改时间', default=datetime.now())
    delete = models.BooleanField('是否删除 0否 1是', default=0)

    def __str__(self):
        return self.b_name

    class Meta:
        db_table = 'bus_user'
        verbose_name_plural = '商家模型类'


# 商品类别表
class CategoryModel(models.Model):
    c_name = models.CharField('商品类别',max_length=64)
    c_img = models.CharField('商品类别图片',max_length=256)
    establish_time = models.DateTimeField('创建时间', default=datetime.now())
    change_time = models.DateTimeField('更改时间', default=datetime.now())
    delete = models.BooleanField('是否删除 0否 1是', default=0)

    def __str__(self):
        return self.c_name

    class Meta:
        db_table = 'category'
        verbose_name_plural = '商品类别'


# 商品表
class GoodsModel(models.Model):
    g_name = models.CharField('商品名称',max_length=64,default='')
    volume = models.IntegerField('销量',default=0)
    inventory = models.IntegerField('库存',default=0)
    price = models.DecimalField('价格',max_digits=13,decimal_places=2,default=0.00)
    img = models.CharField('图片',max_length=900,default='')
    burdening = models.CharField('配料',max_length=900,default='')
    is_recommend = models.BooleanField('是否推荐 1推键 0不推荐',default=0)
    is_demand = models.BooleanField('是否畅销 1畅销 0不畅销',default=0)
    category = models.ForeignKey(to=CategoryModel,on_delete=models.CASCADE,verbose_name='商品所属类别')
    bus_user = models.ForeignKey(to=BusUserModel, on_delete=models.CASCADE, verbose_name="所属商家")
    establish_time = models.DateTimeField('创建时间', default=datetime.now())
    change_time = models.DateTimeField('更改时间', default=datetime.now())
    delete = models.BooleanField('是否删除 0否 1是', default=0)

    class Meta:
        db_table = 'goods'

    def __str__(self):
        return self.g_name






